﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using YaAppoint.ApplyDepartments;

namespace YaAppoint.Web.Controllers
{
    public class ApplyDepartmentController(IApplyDepartmentAppService applyDepartmentAppService) : Controller
    {
        private readonly IApplyDepartmentAppService _applyDepartmentAppService= applyDepartmentAppService;

        /// <summary>
        /// 加载列表
        /// </summary>
        [HttpGet("/api/apply-department/get-list")]
        public async Task<IActionResult> GetListAsync(string? filerName)
        {
            return new JsonResult(await _applyDepartmentAppService.GetList(filerName));
        }

        /// <summary>
        /// 提交新建
        /// </summary>
        [HttpPost("/api/apply-department/submit-create")]
        public async Task<IActionResult> SubmitCreate([FromBody]CreateApplyDepartmentDto dto)
        {
            return new JsonResult(await _applyDepartmentAppService.SubmitCreate(dto));
        }

        /// <summary>
        /// 提交编辑
        /// </summary>
        [HttpPost("/api/apply-department/submit-edit")]
        public async Task<IActionResult> SubmitEdit([FromBody] ApplyDepartmentDto dto)
        {
            return new JsonResult(await _applyDepartmentAppService.SubmitEdit(dto));
        }

        /// <summary>
        /// 删除单个
        /// </summary>
        [HttpGet("/api/apply-department/delete")]
        public async Task<IActionResult> Delete(Guid id)
        {
            return new JsonResult(await _applyDepartmentAppService.Delete(id));
        }

        /// <summary>
        /// 批量删除
        /// </summary>
        [HttpPost("/api/apply-department/delete-many")]
        public async Task<IActionResult> DeleteMany([FromBody]List<Guid> ids)
        {
            return new JsonResult(await _applyDepartmentAppService.DeleteMany(ids));
        }

        /// <summary>
        /// 同步数据
        /// </summary>
        [HttpGet("/api/apply-department/sync-data")]
        public async Task<IActionResult> SyncData()
        {
            var res = await _applyDepartmentAppService.SyncData();
            return new JsonResult(res);
        }

        /// <summary>
        /// 获取详情
        /// </summary>
        [HttpGet("/api/apply-department/get-detail")]
        public async Task<IActionResult> GetDetail(Guid id)
        {
            return new JsonResult(await _applyDepartmentAppService.GetDetail(id));
        }
    }
}
